package com.qfedu.stussm.controller;

import com.qfedu.stussm.entity.Doctor;
import com.qfedu.stussm.entity.Equipment;
import com.qfedu.stussm.service.intf.DoctorService;
import com.qfedu.stussm.service.intf.EquipmentService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/api/equipment/")
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;

//    查询
    @GetMapping("equipmentlist.do")
    @ResponseBody
    public PageBeanVo page(String keyword, int page, int limit){
        System.out.println(keyword);
        return equipmentService.selectAll(keyword, page, limit);
    }
//    新增
    @PostMapping("add.do")
    public R save(Equipment equipment){
        System.out.println(equipment);
        return equipmentService.add(equipment);
    }

    //修改
    @PostMapping("update.do")
    public R update(Equipment equipment){
        System.out.println(equipment);
        return equipmentService.update(equipment);
    }

    //根据id数组删除
    @PostMapping("delbyids.do")
    public R delbyids(String isStr) {
        System.out.println(isStr);
        ArrayList<Integer> ids = new ArrayList<>();
        String[] re_ids = isStr.split(",");
        for (String r_id : re_ids){
            Integer id = Integer.valueOf(r_id);
            ids.add(id);
        }
        return equipmentService.delbyids(ids);
    }


}
